package cn.wolfcode.crud.web.controller;

import cn.wolfcode.crud.domain.CourseOrder;
import cn.wolfcode.crud.domain.Customer;
import cn.wolfcode.crud.domain.Employee;
import cn.wolfcode.crud.domain.SystemDictionaryItem;
import cn.wolfcode.crud.qo.CustomerQuery;
import cn.wolfcode.crud.service.ICourseOrderService;
import cn.wolfcode.crud.service.ICustomerService;
import cn.wolfcode.crud.service.ISystemDictionaryItemService;
import cn.wolfcode.crud.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/CourseOrder")
public class CourseOrderController {

    @Autowired
    private ICourseOrderService courseOrderService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;
    @Autowired
    private ICustomerService customerService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") CustomerQuery qo){

        PageInfo<CourseOrder> pageInfo = courseOrderService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        List<SystemDictionaryItem> subjects = systemDictionaryItemService.selectByParentSn("subject");
        model.addAttribute("subjects", subjects);
        List<Customer> customers = customerService.listAll();
        model.addAttribute("customers",customers);
        return "customer/CourseOrderList";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(CourseOrder courseOrder){
        if (courseOrder.getId() != null) {
            courseOrderService.update(courseOrder);
        }else {
            courseOrderService.save(courseOrder);
        }
        return new JsonResult();
    }

}
